<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:lzc="http://schemas.icitadel.com/Lazarus/Compiled.xsd" version="1.0">

	<xsl:output method="text"/>

	<xsl:include href="../../common.xsl" />
	<xsl:include href="../../convert.xsl" />

   <xsl:template match="lzc:project">
	<!-- Drop the relationship indexes. -->
	<xsl:text>-- Index Deletion
	
</xsl:text>

   <xsl:for-each select=".//lzc:table/lzc:fields/lzc:field[ lzc:indexes/lzc:index/@type = $INDEXTYPE_FOREIGN ]">
		<xsl:variable name="TABLE_NAME">
			<xsl:text>tbl</xsl:text>
			<xsl:value-of select="ancestor::lzc:table/@name" />
		</xsl:variable>
		<xsl:variable name="INDEX_NAME" select="lzc:indexes/lzc:index[ ( @name ) and not( @type = $INDEXTYPE_PRIMARY ) and not( @type = $INDEXTYPE_CLUSTERED ) ]/@name" />

<xsl:text>IF ( EXISTS( SELECT syso.id FROM sysindexes sysi INNER JOIN sysobjects syso ON sysi.id = syso.id WHERE syso.name = '</xsl:text>
<xsl:value-of select="$TABLE_NAME" />
<xsl:text>' AND sysi.name = '</xsl:text>
<xsl:value-of select="$INDEX_NAME" />
<xsl:text>' ) )
   DROP INDEX [</xsl:text><xsl:value-of select="$TABLE_NAME" /><xsl:text>].[</xsl:text><xsl:value-of select="$INDEX_NAME" /><xsl:text>]
GO

</xsl:text>
    </xsl:for-each>

   </xsl:template>

</xsl:stylesheet>
  